package com.egao.orderB.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.orderB.entity.OceanProcess;
import com.egao.orderB.service.OceanProcessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.ui.Model;


/**
 *
 * 海运流程状态
 * @author : Doman
 * @date : 2020-12-07 17:03:04
 * @version ：1.0
 */

@Api(tags = "海运流程状态")
@RestController
@RequestMapping("/api/orderB/oceanProcess")
public class OceanProcessController extends BaseController {

	@Autowired
	private OceanProcessService oceanProcessService;

	/**
	 * 分页查询列表
	 */
	@PreAuthorize("hasAuthority('orderB:oceanProcess:list')")
    //@OperLog(value = "海运流程状态", desc = "分页查询")
    @ApiOperation(value ="分页查询海运流程状态",notes = "" +
            "id:id\n" +
            "organizationId:公司id\n" +
            "oceanId:订单id\n" +
            "state:状态\n" +
            "stateTime:状态时间\n" +
            "remark:备注\n" +
            "createTime:创建时间\n" +
            "createUser:创建人\n" +
            "updateTime:更新时间\n" +
            "updateUser:更新人\n" +
            "deleted:del(0正常 1删除)\n" +
            "",httpMethod = "POST")
    @ApiPageParam
    @PostMapping("/list")
    public JsonResult page(PageResult2<T> page, OceanProcess oceanProcess) throws Exception{
        return oceanProcessService.list(page, oceanProcess, getLoginUser());
    }

    /**
     * 查询全部海运流程状态
     */
    @PreAuthorize("hasAuthority('orderB:oceanProcess:list')")
    //@OperLog(value = "海运流程状态", desc = "查询全部")
    @ApiOperation("查询全部海运流程状态")
    @PostMapping("/listAll")
    public JsonResult list(OceanProcess oceanProcess){
        return oceanProcessService.list(oceanProcess, getLoginUser());
    }

    /**
     * 根据id查询海运流程状态
     */
    @PreAuthorize("hasAuthority('orderB:oceanProcess:list')")
    //@OperLog(value = "海运流程状态", desc = "根据id查询")
    @ApiOperation("根据id查询海运流程状态")
    @PostMapping("/get")
    public JsonResult get(OceanProcess oceanProcess) {
        return oceanProcessService.getById(oceanProcess);
		// 使用关联查询
        //PageParam<oceanProcess> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<oceanProcess> records = oceanProcessService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加海运流程状态
     */
    @PreAuthorize("hasAuthority('orderB:oceanProcess:save')")
    @OperLog(value = "海运流程状态", desc = "添加", param = false, result = true)
    @ApiOperation(value ="添加海运流程状态",notes = "" +
            "oceanId:订单id\n" +
            "state:状态\n" +
            "stateTime:状态时间\n" +
            "remark:备注\n" +
            "",httpMethod = "POST")
    @PostMapping("/save")
    public JsonResult save(Model model, OceanProcess oceanProcess) {
        return oceanProcessService.save(oceanProcess, getLoginUser());
    }

    /**
     * 修改海运流程状态
     */

    @PreAuthorize("hasAuthority('orderB:oceanProcess:update')")
    @OperLog(value = "海运流程状态", desc = "修改", param = false, result = true)
    @ApiOperation(value ="修改海运流程状态",notes = "" +
            "id:id\n" +
            "state:状态\n" +
            "stateTime:状态时间\n" +
            "remark:备注\n" +
            "",httpMethod = "POST")
    @PostMapping("/update")
    public JsonResult update(Model model, OceanProcess oceanProcess) {
        return oceanProcessService.update(oceanProcess, getLoginUser());
    }

    /**
     * 删除海运流程状态
     */
    @PreAuthorize("hasAuthority('orderB:oceanProcess:remove')")
    @OperLog(value = "海运流程状态", desc = "删除", result = true)
    @ApiOperation("删除海运流程状态")
    @PostMapping("/remove")
    public JsonResult remove(OceanProcess oceanProcess ) {
        return oceanProcessService.remove(oceanProcess, getLoginUser());
    }

    /**
     * 批量添加海运流程状态
     */
    /**@RequiresPermissions("orderB:oceanProcess:save")
    @OperLog(value = "海运流程状态", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<OceanProcess> list) {
        if (oceanProcessService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改海运流程状态
     */
    /**@RequiresPermissions("orderB:oceanProcess:update")
    @OperLog(value = "海运流程状态", desc = "批量修改", result = true)
    @ResponseBody
    @PostMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<OceanProcess> batchParam) {
        if (batchParam.update(oceanProcessService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除海运流程状态
     */
    /**@RequiresPermissions("orderB:oceanProcess:remove")
    @OperLog(value = "海运流程状态", desc = "批量删除", result = true)
    @ResponseBody
    @PostMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (oceanProcessService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
